//
//  BezierArrowView.m
//  DrawBezierDemo
//
//  Created by wulanzhou on 16/5/12.
//  Copyright © 2016年 wulanzhou. All rights reserved.
//

#import "BezierArrowView.h"

@implementation BezierArrowView

- (id)initWithFrame:(CGRect)frame{
    if (self=[super initWithFrame:frame]) {
        self.backgroundColor=[UIColor clearColor];
    }
    return self;
}


/**
 *  画三角形与文字
 */
- (void)drawTriangle{
    
    UIColor *color = [UIColor whiteColor];
    [color set];  //设置线条颜色
    
    UIBezierPath* aPath = [UIBezierPath bezierPath];
    //aPath.lineWidth = 0.5;
    
    aPath.lineCapStyle = kCGLineCapButt;  //线条拐角
    aPath.lineJoinStyle = kCGLineJoinRound;  //终点处理
    
    //绘制三角形
    [aPath moveToPoint:CGPointMake(4, 16)];
    [aPath addLineToPoint:CGPointMake(20, 16)];
    [aPath addLineToPoint:CGPointMake(12, 24)];
    
    
    //画文字，设置文字内容
    NSString *text = @"100";
    //设置字体大小
    UIFont *font = [UIFont systemFontOfSize:10];
    
    if ([text respondsToSelector:@selector(drawInRect:withAttributes:)]) {
        NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
        paragraphStyle.lineBreakMode = NSLineBreakByClipping;
        paragraphStyle.alignment = NSTextAlignmentCenter;
        
        NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys: font, NSFontAttributeName,[UIColor whiteColor],NSForegroundColorAttributeName,paragraphStyle,NSParagraphStyleAttributeName,nil];
        [text drawInRect:CGRectMake(0, 2, self.bounds.size.width, 12) withAttributes:dictionary];
    }else{
        //6.0以下处理
        [text drawInRect: CGRectMake(0, 2, self.bounds.size.width, 12)
                withFont: font
           lineBreakMode: NSLineBreakByTruncatingTail
               alignment: NSTextAlignmentCenter];
    }

    [aPath closePath]; //第五条线通过调用closePath方法得到的
    [aPath fill];
    [aPath stroke]; //Draws line 根据坐标点连线
    
}


- (void)drawRect:(CGRect)rect {
    [self drawTriangle];
}


@end
